<template>
  <ych-modal
    :fullscreen="false"
    :title="title"
    :visible="visible"
    :destroyOnClose="true"
    @cancel="handleCancel">

    <act-app-http-view-list ref="comp" :radio="radio" :groupId="groupId" @selected="handleOk" :httpMethod="httpMethod"></act-app-http-view-list>

    <template slot="footer">
      <a-button key="back" @click="handleCancel">{{ $t('m.common.button.close') }}</a-button>
      <a-button key="handleClear" @click="handleClear">{{ $t('m.common.button.clear') }}</a-button>
      <a-button key="submit" type="primary" @click="handleOk">{{ $t('m.common.button.ok') }}</a-button>
    </template>
  </ych-modal>
</template>

<script>

import ActAppHttpViewList from '../list/ActAppHttpViewList'

export default {
  name: 'SelectHttpViewDialog',
  components: {
    ActAppHttpViewList
  },
  props: {
    groupId: {
      type: String,
      required: false
    },
    httpMethod: String,
  },
  data() {
    return {
      title: this.$t('m.eform.formDesign.label.xuan-ze-fu-wu-pei-zhi'),
      visible: false,
      radio: false,
    }
  },
  methods: {
    handleCancel() {
      this.visible = false
      this.radio = false
    },
    handleOk() {
      if (this.$refs.comp.selectedRowKeys.length === 0) {
        this.messageUtil.warning(this.$t('m.eform.formDesign.label.qing-xuan-ze-shu-ju'))
        return
      }
      this.$emit('selectFinished', this.$refs.comp.selectedRowKeys, this.$refs.comp.selectionRows)
      this.handleCancel()
    },
    handleClear() {
      this.$emit('selectFinished')
      this.handleCancel()
    },
  }
}
</script>
